package com.itheima.health.dao;

import com.itheima.health.pojo.Member;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.Date;

/**
 * @author deng
 * @package com.itheima.health.dao
 * @date Created in 2024/7/14 16:43
 */
public interface MemberDao {
    @Select("select * from t_member where phoneNumber = #{telephone}")
    Member findByTelephone(String telephone);

    @Insert("insert into t_member values (null, #{fileNumber}, #{name}, #{sex}, #{idCard}, #{phoneNumber}, #{regTime}, #{password}, #{email}, #{birthday}, #{remark})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(Member member);

    @Select("select name from t_member where id = #{memberId}")
    String findNameById(Integer memberId);

    /**
     * 今日新增会员数
     * @param today
     * @return
     */
    @Select("select count(*) from t_member where regTime = date(#{today});")
    Integer findMemberCountByDate(Date today);

    /**
     * 总会员数
     * @return
     */
    @Select("select count(*) from t_member;")
    Integer findMemberTotalCount();

    /**
     * 查询指定时间之后的会员数量
     * @param date
     * @return
     */
    @Select("select count(*) from t_member where regTime >= date(#{date});")
    Integer findMemberCountAfterDate(Date date);


    @Select("select count(*) from t_member where #{startDate}<=regTime and regTime<= #{endDate};")
    int findMemberCountByMonth(Date startDate,Date endDate);
}
